package com.eastfair.venueservice.service.impl;

//import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.eastfair.boot.service.SuperServiceImpl;
import com.eastfair.constant.BusinessConstant;
import com.eastfair.core.base.R;
import com.eastfair.core.context.ContextUtil;
import com.eastfair.venueservice.dao.ServiceItemDetailMapper;
import com.eastfair.venueservice.entity.ServiceItemDetail;
import com.eastfair.venueservice.service.ServiceItemDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Objects;
/**
 * <p>
 * 业务实现类
 * 服务项明细
 * </p>
 *
 * @author linan
 * @date 2022-07-13
 */
@Slf4j
@Service
//@DS("#thread.tenant")
public class ServiceItemDetailServiceImpl extends SuperServiceImpl<ServiceItemDetailMapper, ServiceItemDetail> implements ServiceItemDetailService {


    /**
     * 处理逻辑删除相关处理
     *
     * @param modelList 实体
     * @return 是否成功
     */
    @Override
    protected R<Boolean> handlerRemoveByIdsOfLogic(Collection<ServiceItemDetail> modelList) {
        modelList.stream().forEach(s -> {
            s.setIsDeleted(BusinessConstant.YES);
        });
        // TODO: 2021/10/29 这里需要操作其他业务，如清空角色等
        return R.successDef();
    }

    @Override
    protected R<Boolean> handlerSave(ServiceItemDetail model) {
        model.setProjectId(ContextUtil.getProjectId());
        model.setSubsystemId(ContextUtil.getSubSystemId());
        model.setTenantId(ContextUtil.getTenantId());
        return R.successDef();
    }

    /**
     *
     * @param serviceItemId
     * @return
     */
    @Override
    public  List<ServiceItemDetail> getServiceItemDetailByServiceItemId(Long serviceItemId) {
        QueryWrapper<ServiceItemDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(Objects.nonNull(serviceItemId),ServiceItemDetail::getServiceItemId,serviceItemId)
                .eq(ServiceItemDetail::getIsDeleted,BusinessConstant.DELETE_NO);
        List<ServiceItemDetail> serviceItemDetailList = this.list(queryWrapper);
        return serviceItemDetailList;
    }
}
